<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: aqua;
        }
    </style>
</head>

<body>
    <div class="box">

    </div>
    <button class="btn">
        按钮
    </button>
</body>
<script>
    var box = document.querySelector('.box');
    var btn = document.querySelector('.btn');
    var a = true;
    btn.onclick = function () {
        if (a) {
            box.setAttribute('style', 'display:none');
        } else {
            box.setAttribute('style', 'display:block');
        }
        a = !a;
    }
        ;
</script>

</html>